package crazyboyfeng.autodroid.ui;

import crazyboyfeng.autodroid.R;
import crazyboyfeng.autodroid.utils.GlobalContext;

import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast;
public class SettingFragment extends PreferenceFragment{
	
	 @Override
     public void onCreate(final Bundle savedInstanceState){
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.setting_preference);
     }
	 
	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
		String key=preference.getKey();
			if(key.equals("update_key")){
				Toast.makeText(GlobalContext.getInstance(), "正在检查更新……",Toast.LENGTH_SHORT).show();
				preference.setEnabled(false);
				preference.setSummary("当前版本已为最新");
				Toast.makeText(GlobalContext.getInstance(), "尚无更新版本！",Toast.LENGTH_SHORT).show();
				return true;
			}else if(key.equals("about_key")){
				preference.setTitle("感谢捐助");
				preference.setSummary(null);
				Toast.makeText(GlobalContext.getInstance(), "版权所有 © 2013 狂男风。",Toast.LENGTH_SHORT).show();
				Toast.makeText(GlobalContext.getInstance(), "保留所有权利。",Toast.LENGTH_SHORT).show();
				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.alipay.com/personal/payment.htm?userId=2088002615292144&reason=%E6%9C%9B%E8%87%AA%E5%8A%A8%E4%BB%BB%E5%8A%A1%E8%83%BD%E7%BB%A7%E7%BB%AD%E5%89%8D%E8%A1%8C&weChat=true")));
		        return true;
			}else if(key.equals("home_key")){
				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://droidcon.googlecode.com/")));
		        return true;
			}else if(key.equals("gpl_key")){
				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.thebigfly.com/gnu/gpl/")));
		        return true;
			}
			return super.onPreferenceTreeClick(preferenceScreen, preference);
	}
}
